package com.yeyks.commonReference.service.hotel.impl;

import com.yeyks.commonReference.service.hotel.HotelSearchUtilService;
import com.yeyks.hotel.dal.dao.HotelInfoMapper;
import com.yeyks.hotel.vo.HotelInfoHotelSearchVoHotle;
import com.yeyks.hotel.vo.HotelInfoHotelSearchVoRoom;
import com.yeyks.hotel.vo.HotelInfoHotelSearchVoRoomCalendar;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.Iterator;
import java.util.List;

@Service
public class HotelSearchUtilServiceImpl implements HotelSearchUtilService {

    @Autowired
    private HotelInfoMapper hotelInfoMapper;

    //填充房间的最低价和房间数量
    @Override
    public void perfectHotelInfoB2cHotelSearchVoRoomsAttribute(HotelInfoHotelSearchVoHotle hotelInfoHotelSearchVoHotle, Date startTime, Date endTime) {
        //房态
        List<HotelInfoHotelSearchVoRoomCalendar> hotelInfoB2cHotelSearchVoRoomCalendars = hotelInfoMapper.b2cHotelSearchRoomCalendars(startTime, endTime, hotelInfoHotelSearchVoHotle.getRoomIds());
        List<HotelInfoHotelSearchVoRoom> rooms = hotelInfoHotelSearchVoHotle.getRooms();
        Iterator<HotelInfoHotelSearchVoRoom> iterator = rooms.iterator();
        out: while (iterator.hasNext()){
            HotelInfoHotelSearchVoRoom hotelInfoB2cHotelSearchVoRoom = iterator.next();
            for (HotelInfoHotelSearchVoRoomCalendar hotelInfoB2cHotelSearchVoRoomCalendar : hotelInfoB2cHotelSearchVoRoomCalendars) {
                if (hotelInfoB2cHotelSearchVoRoom.getId().equals(hotelInfoB2cHotelSearchVoRoomCalendar.getRoomId())) {
                    hotelInfoB2cHotelSearchVoRoom.setMinCount(hotelInfoB2cHotelSearchVoRoomCalendar.getMinCount());
                    hotelInfoB2cHotelSearchVoRoom.setMinPrice(hotelInfoB2cHotelSearchVoRoomCalendar.getMinPrice());
                    continue out;
                }
            }
            iterator.remove();
        }
    }
}
